package com.x.crm.dao;

import com.x.crm.model.FollowService;
import com.x.crm.model.FollowUp;
import com.x.framework.dao.BaseDao;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

@Repository
public class FollowServiceDao extends BaseDao{


	private final static String baseSelectServiceListSql = "SELECT * FROM  CRM_FOLLOW_SERVICE  I " +
			"WHERE 1=1 ";

	public List<FollowService> selectServiceList(FollowService followService) throws Exception {
		StringBuilder sb = new StringBuilder(baseSelectServiceListSql);
		List<Object> params = new ArrayList<Object>();
		searchBasicCondition(followService, sb, params);
		sb.append(" ORDER BY I.SERVICE_CREATE_TIME DESC");
		return this.queryForList(sb.toString(), FollowService.class, params, followService);
	}


	private void searchBasicCondition(FollowService followService, StringBuilder sb, List<Object> params) {
		if (this.isString(followService.getFollowTypeId())) {
			sb.append("AND I.FOLLOW_TYPE_ID = ? ");
			params.add(followService.getFollowTypeId());
		}
		if (this.isString(followService.getFollowType())) {
			sb.append("AND I.FOLLOW_TYPE = ? ");
			params.add(followService.getFollowType());
		}
	}


}
